import time

from selenium.webdriver.common.by import By

from common.Utils import ForumDriver

class MessageAlertTest:
    url=""
    driver=""

    def __init__(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)
    #成功回复消息
    def SendMessageSuc(self):
        #点击消息提醒按钮，查看消息列表
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg").click()
        # 点击消息标题，输入文本，是否正常回复消息
        # 点击标题
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a > span:nth-child(2)").click()
        # 到了消息详情页，点击“回复”
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_message_reply").click()
        # 找到回复框，输入“这是回复消息”
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_reply_receive_content").send_keys("这是回复信息")
        # 点击“发送”
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_send_message_reply").click()
        # 提示发送成功
        print(self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").text)
        # 截图
        ForumDriver.getScreenShot()

    def SendMessageFail(self):
        # 点击消息提醒按钮，查看消息列表
        self.driver.find_element(By.CSS_SELECTOR,
                                 "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg").click()
        # 点击标题
        self.driver.find_element(By.CSS_SELECTOR,
                                 "#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a > span:nth-child(2)").click()
        # 到了消息详情页，点击“回复”
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_message_reply").click()
        # 不输入内容，直接点击“发送”
        self.driver.find_element(By.CSS_SELECTOR, "#btn_index_send_message_reply").click()
        # 提示输入发送内容
        print(self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").text)
        # 截图
        ForumDriver.getScreenShot()


